package com.atguigu.lease.app.controller;


import com.atguigu.lease.app.configure.WebAppAuthInterceptor;
import com.atguigu.lease.app.service.UserLoginService;
import com.atguigu.lease.model.dto.app.LoginSubmitDto;
import com.atguigu.lease.model.result.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "移动端用户登录模块")
@RestController
@RequestMapping("/app")
public class UserLoginController {

    @Autowired
    UserLoginService userLoginService;

    @Operation(summary = "获取手机验证码")
    @GetMapping("/login/getCode")
    public Response getCode(@RequestParam("phone") String phone){

        userLoginService.getCode(phone);

        return Response.ok(null);
    }

    @Operation(summary = "登录")
    @PostMapping("/login")
    public Response<String> login(@RequestBody LoginSubmitDto loginSubmitDto){
        String token = userLoginService.login(loginSubmitDto);

        return Response.ok(token);
    }

    @Operation(summary = "登陆成功查看用户个人信息")
    @GetMapping("/info")
    public Response info(){
        Map<String, Object> map = WebAppAuthInterceptor.THREAD_LOCAL.get();
        return Response.ok(map);
    }

}
